<template>
  <div id="UserTable">
    <el-table
      border style="width: 100%"
      empty-text="暂无用户数据"
      :data="userData"
    >
      <el-table-column
        width="300"
        label="客户名称">
        <template slot-scope="scope">
          <div style="display: flex">
            <div class="table_left_img_block" style="border-radius: 50%; overflow: hidden">
              <img style="border-radius: 50%;" width="60px" height="60px" :src="scope.row.passportAccountInfo.avatar | handleImgSize" alt="">
            </div>
            <div class="table_left_img_block" style="position: relative; flex: 1; padding-left: 10px">
              <span  style="display: block; position: absolute; top: 50%; transform: translateY(-50%)">
                {{scope.row.passportAccountInfo.nickname}}
                <i v-if="scope.row.passportAccountInfo.fullname">（{{scope.row.passportAccountInfo.fullname}}）</i>
              </span>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="telephone"
        label="手机号">
      </el-table-column>
      <el-table-column
        label="会员等级">
        <template slot-scope="scope">
          {{scope.row.passportLevel.level | handleLevelENum}}
        </template>
      </el-table-column>
      <el-table-column
        prop="passportCredit.currValue"
        label="积分数">
      </el-table-column>
      <el-table-column
        prop="totalPrice"
        label="消费金额">
      </el-table-column>
      <el-table-column
        prop="serviceNames"
        label="主要治疗项目">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="建档时间">
      </el-table-column>
      <el-table-column
        label="渠道">
        <template slot-scope="props">
          {{props.row.userType | handleUserType}}
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
      >
        <template slot-scope="scope">
          <el-button
            type="text" size="small"
            @click.stop="$emit('lookDetailBtnClick', scope.row.id)"
          >查询详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      layout="prev, pager, next"
      :page-count="pageInfo.pageCount"
      :page-size="pageInfo.pageSize"
      :current-page="pageInfo.currentPage"
      @current-change="changeCurrentPage"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'UserTable',
  props: [
    'userData', 'pageInfo'
  ],
  filters: {
    handleUserType: (value) => { // 过滤状态显示
      let txt = ''
      switch (value) {
        case 1:
          txt = '系统自建'
          break
        case 2:
          txt = '小程序注册'
          break
        case 3:
          txt = '直接来院'
          break
        case 4:
          txt = '员工推荐'
          break
        case 5:
          txt = '客户推荐'
          break
      }
      return txt
    },
    handleImgSize: (value) => {
      return `${value}?imageView2/1/w/60/h/60`
    },
    handleLevelENum: value => {
      switch (value) {
        case 1:
          return '初级会员'
      }
    }
  },
  methods: {
    changeCurrentPage (e) {
      this.$emit('currentChange', e)
    }
  }
}
</script>

<style scoped lang="scss">
  .demo-table-expand {
    font-size: 0;
    label {
      width: 90px;
      color: #99a9bf;
    }
    .el-form-item {
      margin-right: 0;
      margin-bottom: 0;
      width: 33.33%;
    }
  }
  .el-button {
    margin: 0 10px 0 0;
  }
  .el-pagination {
    margin-top: 20px;
    text-align: center;
  }
</style>
